<template>        
  <el-form-item  v-model="organizationId">
            <el-tree-select
              v-model="organizationId"
              :data="organizationList"
              :props="defaultProps"
              check-strictly
              node-key="id"
              placeholder="请选择归属部门"
            />
  </el-form-item>
</template>
<script lang="ts" setup>
import { OrganizationApi } from '@/api/member/organization'
import { defaultProps, handleTree } from '@/utils/tree'


/** 会员分组选择框 **/
defineOptions({ name: 'MemberOrganizationSelect' })

const props = defineProps({
  /** 下拉框选中值 **/
  modelValue: {
    type: Number,
    default: undefined
  }
})
const organizationList = ref<Tree[]>([]) // 树形结构

const emit = defineEmits(['update:modelValue'])

const organizationId = computed({
  get() {
    return props.modelValue
  },
  set(value: any) {
    emit('update:modelValue', value)
  }
})

// const organizationOptions = ref<OrganizationVO[]>([])

const getList = async () => {
  organizationList.value = handleTree(await OrganizationApi.getOrganizationList({}))
}

/** 初始化 */
onMounted(() => {
  getList()
})
</script>
